package com.socialuni.sdk.domain;

import com.socialuni.sdk.model.DO.user.UserDO;
import com.socialuni.sdk.utils.SocialUniProviderUtil;
import com.socialuni.sdk.exception.UniSdkException;
import com.socialuni.sdk.model.ProviderLoginQO;
import com.socialuni.sdk.model.UniUnionIdRO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SocialUserDODomainCreate {
    @Resource
    UserProviderLoginDomain userProviderLoginDomain;
    //根据渠道登录信息获取user，支持social比commonUserDomain
    //这个单独出来是因为区分了基础provider和社交，这个单独增加了对社交渠道的支持
    public UserDO getOrCreate(ProviderLoginQO loginQO) {
        UniUnionIdRO uniUnionIdRO = SocialUniProviderUtil.getUnionIdRO(loginQO);
        if (uniUnionIdRO.hasError()){
            throw new UniSdkException("获取openId失败");
        }
        return userProviderLoginDomain.getOrCreate(loginQO, uniUnionIdRO);
    }
}
